package com.stony.core.struts.tag;

import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.struts.taglib.TagUtils;

public class MessageMarqueeTag extends TagSupport {

	protected String size = "10";
	
	protected String direction = "left";
	
	protected String speed = "4";
	
	protected String width = "420";
	
	protected String height = "";

	public int doEndTag() throws JspException {

		// JspWriter out = pageContext.getOut();
		
		List systemmessages = (List)pageContext.getRequest().getAttribute("systemmessages");
		
		StringBuffer outStr = new StringBuffer(512);
		
		outStr.append("<marquee scrollAmount=\"");
		
		outStr.append(speed);
		
		outStr.append("\" width=\"");
		
		outStr.append(width);
		
		outStr.append("\" height=\"");
		
		outStr.append(height);
		
		outStr.append("\" onmouseover=stop() onmouseout=start()>");
				
		if(systemmessages != null && !systemmessages.isEmpty()){
		
			for(int i=0;i<systemmessages.size();i++){
				
				//PubDocument document = (PubDocument)systemmessages.get(i);
				outStr.append("   <a href=\"systemmessage.do?condition.documentno=");
				//outStr.append(document.getDocumentno());
				outStr.append("\">");
				//outStr.append(i+1+". "+document.getTitle());
				outStr.append("</a>");
				outStr.append("&nbsp;&nbsp;&nbsp;&nbsp;");
			}
			
		}

		outStr.append("</marquee>");

		try {

			TagUtils.getInstance().write(pageContext, outStr.toString());

		} catch (JspException e) {

			TagUtils.getInstance().saveException(pageContext, e);

			throw e;

		}

		return (EVAL_PAGE);

	}

	public int doStartTag() throws JspException {

		return (EVAL_BODY_INCLUDE);

	}

	/**
	 * Release all allocated resources.
	 */
	public void release() {

		super.release();
		direction = null;
		height = null;
		width = null;
		size = null;
		speed = null;
	}

	public String getDirection() {
		return direction;
	}

	public void setDirection(String direction) {
		this.direction = direction;
	}

	public String getHeight() {
		return height;
	}

	public void setHeight(String height) {
		this.height = height;
	}

	public String getSize() {
		return size;
	}

	public void setSize(String size) {
		this.size = size;
	}

	public String getSpeed() {
		return speed;
	}

	public void setSpeed(String speed) {
		this.speed = speed;
	}

	public String getWidth() {
		return width;
	}

	public void setWidth(String width) {
		this.width = width;
	}



}
